var app=new Vue({
    el: '#app',
    data:{
        dept:{
        },
        isDisabled: false,
        dicts:{
            deptType:  []
        },
        deptRules: {
            deptName: [
                { required: true, message: '请输入部门名称', trigger: 'blur' }
            ],
            deptAddress: [
                {  message: '请输入部门地址', trigger: 'blur' }
            ],
            deptPhone: [
                {validator: validatePhone, trigger: 'blur' }
            ],
            deptType: [
                { required: true, message: '请选择部门类型', trigger: 'change' }
            ],
            remark: [
                { max:100, message: '备注最大长度为100', trigger: 'blur' }
            ]
        }
    },
    methods:{
        init: function(){
            var _this=this;
            setTimeout(function(){
                _this.initDict();
            },100);
        },
        closeDialog: function(){
            jsmile.dialog.close();
        },
        /**
         * 初始化数据字典
         */
        initDict: function(){
            var _this=this;
            jsmile.http.sendJson({
                url:jsmile.url+"/sys/dict/findDictByCode",
                data:{"dictCode":"DT01"}
            }).done(function(res){
                _this.dicts.deptType=res.resData;
            });
        },
        updateDict: function(){
            var _this=this;
            _this.isDisabled=true;
            this.$refs['dept'].validate(function(valid) {
                if (valid) {
                    jsmile.http.sendJson({
                        url:jsmile.url+"/sys/dept/update",
                        data:_this.dept
                    }).done(function(res){
                        top.$('#home')[0].contentWindow.app.init();
                        jsmile.msg.success("修改部门成功");
                        jsmile.dialog.close();
                    }).fail(function(res){
                        jsmile.msg.error(res.resMsg?res.resMsg:"修改部门失败!");
                    });
                } else {
                    return false;
                }
            });
        }
    }
});
$(function(){
    init();
    function init(){
        app.init();
    }
});